home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_319 / cnewssrc / uupc.lzh / uupc / timer.c < prev    next >
C/C++ Source or Header  |  1990-01-16  |  3KB  |  129 lines

  1. /*  
  2.  *    Timer.c: Functions to invoke the Amiga timer
  3.  *    05Jul86  - Created by Jeff Lydiatt, Vancouver, Canada.
  4.  *
  5.  *    Amiga Library
  6.  *
  7.  *    $Id: timer.c,v 1.2 90/01/16 10:27:38 crash Exp Locker: crash $
  8.  */
  9.  
  10. #ifndef lint
  11. static char RCSid[] = "$Id: timer.c,v 1.2 90/01/16 10:27:38 crash Exp Locker: crash $";
  12. #endif /* lint */
  13.  
  14. #include <exec/types.h>
  15. #include <exec/nodes.h>
  16. #include <exec/lists.h>
  17. #include <exec/ports.h>
  18. #include <exec/tasks.h>
  19. #include <exec/io.h>
  20. #include <devices/timer.h>
  21.  
  22. #ifdef MCH_AMIGA
  23. # include <functions.h>        /* Manx */
  24. #else
  25. # include <proto/exec.h>    /* Lattice */
  26. #endif
  27.  
  28. static struct timerequest TimerIO;
  29. static struct MsgPort *TimerPort = NULL;
  30. static BOOL timerON;
  31. static BOOL timerExpired;
  32.  
  33. /*--------------------------------------------------------------*/
  34. /*    OpenTimer: return TRUE if timer opened OK                    */
  35. /*--------------------------------------------------------------*/
  36.  
  37. BOOL OpenTimer()
  38. {
  39.     register struct timerequest *t = &TimerIO;
  40.     register struct MsgPort *port;
  41.  
  42.     timerON = FALSE;
  43.     timerExpired = TRUE;
  44.     if (TimerPort != NULL)
  45.         return TRUE;
  46.  
  47.     if ((port = CreatePort("Timer Port", 0L)) == NULL)
  48.         return FALSE;
  49.     else
  50.         TimerPort = port;
  51.  
  52.     if (OpenDevice(TIMERNAME, UNIT_VBLANK, t, 0L)) {
  53.         DeletePort(port);
  54.         TimerPort = NULL;
  55.         return FALSE;
  56.     }
  57.     return TRUE;
  58. }
  59.  
  60.  
  61. /*--------------------------------------------------------------*/
  62. /*    CloseTimer: All Done with the timer.                        */
  63. /*--------------------------------------------------------------*/
  64.  
  65. void CloseTimer()
  66. {
  67.     register struct timerequest *t = &TimerIO;
  68.  
  69.     if (timerON) AbortIO(t);
  70.  
  71.     CloseDevice(t);
  72.     DeletePort(TimerPort);
  73.     TimerPort = NULL;
  74. }
  75.  
  76.  
  77. /*--------------------------------------------------------------*/
  78. /*    GetTimerSigBit: return Timer signal bit                        */
  79. /*--------------------------------------------------------------*/
  80.  
  81. int    GetTimerSigBit()
  82. {
  83.     return TimerPort->mp_SigBit;
  84. }
  85.  
  86.  
  87. /*--------------------------------------------------------------*/
  88. /*    StartTimer: launch the timer.                                */
  89. /*--------------------------------------------------------------*/
  90.  
  91. void StartTimer(seconds, micros)
  92. ULONG seconds, micros;
  93. {
  94.     register struct timerequest *t = &TimerIO;
  95.  
  96.     if (timerON) {
  97.         AbortIO(t);
  98.         (void) GetMsg(TimerPort);
  99.         timerON = FALSE;
  100.         timerExpired = TRUE;
  101.     }
  102.     t->tr_time.tv_secs    = seconds;
  103.     t->tr_time.tv_micro   = micros;
  104.     t->tr_node.io_Command = TR_ADDREQUEST;
  105.     t->tr_node.io_Flags   = IOF_QUICK;
  106.     t->tr_node.io_Error   = 0;
  107.     t->tr_node.io_Message.mn_ReplyPort = TimerPort;
  108.     SendIO(t);
  109.     timerExpired = FALSE;
  110.     timerON = TRUE;
  111. }
  112.  
  113.  
  114. /*--------------------------------------------------------------*/
  115. /*    TimerExpired: returns TRUE if timer expired.                */
  116. /*--------------------------------------------------------------*/
  117.  
  118. BOOL TimerExpired()
  119. {
  120.     if (timerON && (CheckIO(&TimerIO.tr_node) == NULL))
  121.         return FALSE;
  122.  
  123.     (void) GetMsg(TimerPort);
  124.     timerExpired = TRUE;
  125.     timerON = FALSE;
  126.  
  127.     return timerExpired;
  128. }
  129.